package org.apache.jmeter.gui.rcp.tree;

import java.util.ArrayList;
import java.util.List;

public class JMeterTreeNode implements NamedTreeNode {
	private String name;
	private JMeterTreeNode parent;
	private List children;
	private String imageName = null;

	public JMeterTreeNode(String name) {
		this.name = name;
	}
	public JMeterTreeNode(String name, String imageName) {
		this.setName(name);
		this.setImageName(imageName);
	}
	public String getImageName() {
		return imageName;
	}
	public void setImageName(String imageName) {
		this.imageName = imageName;
	}
	public String getName() {
		return name;
	}
	public void setParent(JMeterTreeNode parent) {
		this.parent = parent;
	}
	public JMeterTreeNode getParent() {
		return parent;
	}
	public String toString() {
		return getName();
	}
	
	public void addChild(JMeterTreeNode child) {
		if (children == null || children.size() <= 0) {
			children = new ArrayList();
		}
		children.add(child);
		child.setParent(this);
	}
	public void removeChild(JMeterTreeNode child) {
		if (children == null || children.size() <= 0) {
			return;
		}
		children.remove(child);
		child.setParent(null);
	}
	public JMeterTreeNode[] getChildren() {
		if (this.isParent()) {
			return (JMeterTreeNode[]) children.toArray(new JMeterTreeNode[children.size()]);
		} else {
			return new JMeterTreeNode[0];
		}
	}
	public boolean hasChildren() {
		if (children == null || children.size() <= 0) {
			return false;
		}
		
		return children.size()>0;
	}
	public boolean isParent() {
		return (children != null && children.size() > 0);
	}
	public void nameChanged() {
		// TODO Auto-generated method stub
		
	}
	public void setName(String name) {
		this.name = name;
	}
}
